package model

import (
	"time"
)

const (
	KeySwap = iota
	Tran
	Boradcast
	Tick
)

type Trans struct {
	PackInfo Head
	TransId  string
	PackType int
	Data     []byte
	Sign     []byte
}

func (a *Trans) GetByte() ([]byte, error) {
	return Encode(&a)
}

func (a *Trans) GetData(data []byte) (*Trans, error) {
	err := Decode(data, &a)
	return a, err
}

func (a *Trans) CreatPackInfo(data, sign []byte, creater, receiver string) {
	packinfo := &a.PackInfo
	packinfo.Lengh = len(data)
	packinfo.TimeStamp = time.Now().Unix()
	packinfo.Sender = creater
	packinfo.Receiver = receiver
	packinfo.Sign = sign
	packinfo.Trans = append(packinfo.Trans, creater)
	a.Data = data
	a.TransId = creater
}
